﻿@model IEnumerable<TaskManager.Domain.BusinessObjects.Task>
@using MvcContrib.UI.Grid
@using MvcContrib.Pagination
@using TaskManager.Web.Extensions

@{
    ViewBag.Title = "All Tasks";
}

<asp:content id="Content3" contentplaceholderid="head" runat="server">
  <script src="@Url.Content("~/Scripts/Grid.js")" type="text/javascript"></script>
</asp:content>

<script type="text/javascript">
    $(function () {
        EnableAjaxForGrid('taskList');

        $('#showClosedTasks').click(function () {
            var showFlag = false;

            if ($(this).is(':checked'))
                showFlag = true;

            // Use GET to let this request to be cached
            $.get("/Task/Index", { showClosedTasks: showFlag }, function (data) {
                $('#taskList').html(data);
            });
        });
    });
</script>
@using (Html.BeginForm())
{
    <fieldset class="well">
        <div class="row">
            <div class="span3" style="width: auto; margin-top: 5px">
                @if (ViewBag.showClosedTasks)
                {
                    <input type="checkbox" id="showClosedTasks" checked="true" value="Show Closed tasks" />
                }
                else
                {
                    <input type="checkbox" id="showClosedTasks" value="Show Closed tasks" />
                }
                <span>Show Closed tasks</span>
            </div>
        </div>
    </fieldset>
}
<br />

<div id="taskList">
@{
    Html.Grid(Model)
        .Sort(ViewBag.sort as GridSortOptions)
        .Attributes(@class => "zebra-striped")
        .Empty("There are no tasks available")
        .Columns(column =>
        {
            column.For(task => Html.ActionLink(task.Summary, "Details", new { id = task.Id })).Named("Summary");
            column.For(task => task.Description).Named("Description").Sortable(false);
            column.For(task => task.Project.Name).Named("Project").Sortable(false);
            column.For(task => task.Assignee).Named("Assignee").Sortable(true);
            column.For(task => task.Owner).Named("Owner").Sortable(true);
            column.For(task => task.Priority).Named("Priority").Sortable(true);
            column.For(task => Html.DisplayFor(m => task.State)).Named("State").Sortable(false);
            column.For(task => task.Updated).Named("Last Modified").Sortable(true);
        }).Render();  
}
@Html.Pager((IPagination)Model, 10, (linkText, routeValues) => Html.ActionLink(linkText, ViewContext.RouteData.Values["Action"].ToString(), routeValues).ToString())
</div>
